<?php
function cookie_get($key)
{
	$key = COOKIE_PREFIX.$key;
	return isset($_COOKIE[$key]) ? $_COOKIE[$key] : '';
}

function cookie_set($key, $value, $time='')
{
	$key = COOKIE_PREFIX.$key;
	
	$expire = 0;

	if($time)
	{
		$expire = time() + $time;
	}
	else
	{
		$expire = time() + COOKIE_TIMEOUT;
	}

	@setcookie($key, $value, $expire, COOKIE_PATH, COOKIE_DOMAIN);
	
	return true;
}

function cookie_delete($key)
{
	$keys = func_get_args();
	
	foreach ($keys as $key)
	{
		cookie_set($key, '', time()-3600);
	}
}

function cookie_clear()
{
	$prefix_len = strlen(COOKIE_PREFIX);
	foreach ($_COOKIE as $key=>$value)
	{
		$name = substr($key, $prefix_len);
		cookie_set($key, '', time()-3600);
	}
}